package com.hue.springbootjwt.controller;

import com.hue.springbootjwt.domain.User;
import com.hue.springbootjwt.service.UserService;
import com.hue.springbootjwt.utils.JwtUtils;
import com.hue.springbootjwt.utils.R;
import com.hue.springbootjwt.utils.RedisUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashSet;
import java.util.Set;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public R login(@Valid @RequestBody User user) {
        String result = userService.login(user);
        return result != null ? R.ok().put("data", result) : R.error("用户名或密码错误");
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request) {
        System.out.println(request);
        return null;
    }
}
